package com.solo.system.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.solo.common.core.global.R;
import com.solo.common.logger.annotation.Logger;
import com.solo.common.logger.enums.LoggerType;
import com.solo.system.model.role.req.RoleDeptReq;
import com.solo.system.service.SysRoleDeptService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 数据权限控制器
 * @author 十一
 * @since 2024-11-07 09:18
 * 人生若只如初见，何事秋风悲画扇
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/role-dept")
public class SysRoleDeptController {

    private final SysRoleDeptService sysRoleDeptService;

    /**
     * 分配数据
     * @param req 请求对象
     * @return {@link R }<{@link Boolean }>
     */
    @PutMapping("/assign")
    @SaCheckPermission("system-role-dept-assign")
    @Logger(value = "分配数据权限", type = LoggerType.UPDATE)
    public R<Boolean> assignData(@Valid @RequestBody RoleDeptReq req) {
        return R.success(sysRoleDeptService.assignData(req));
    }

    @GetMapping("/{roleId}")
    @SaCheckPermission("system-role-dept-assign")
    public R<Set<Long>> menuIds(@PathVariable("roleId") Long roleId) {
        return R.success(sysRoleDeptService.selectDeptIds(roleId));
    }

}
